namespace QMVnSoft.Controls
{
    using QMVnSoft;
    using QMVnSoft.Controls.ChildGridControls;
    using QMVnSoft.Invoices;
    using QMVnSoft.Properties;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormHistoryLister : FormControl
    {
        private ToolStripButton btnClose;
        private ToolStripButton btnFilter;
        private ToolStripButton btnRestore;
        private ToolStripButton btnView;
        private DataGridViewTextBoxColumn Column1;
        private DataGridViewTextBoxColumn Column10;
        private DataGridViewTextBoxColumn Column11;
        private DataGridViewTextBoxColumn Column12;
        private NumericColumn Column13;
        private DataGridViewTextBoxColumn Column14;
        private DataGridViewTextBoxColumn Column15;
        private DataGridViewTextBoxColumn Column2;
        private DataGridViewTextBoxColumn Column3;
        private DataGridViewTextBoxColumn Column4;
        private DataGridViewTextBoxColumn Column5;
        private DataGridViewTextBoxColumn Column6;
        private DataGridViewTextBoxColumn Column7;
        private DataGridViewTextBoxColumn Column8;
        private DataGridViewTextBoxColumn Column9;
        private IContainer components;
        private GridControl grdDetail;
        private GridControl grdMaster;
        private SplitContainer GridContainer;
        private object id_Ngay_Ct1;
        private object id_Ngay_Ct2;
        private string is_HistoryType;
        private string is_InvoiceOrder;
        private DataTable oDetailTable;
        private AppInvoiceLib oAppInvoiceLib;
        private DataTable oMasterTable;
        private ToolStripSeparator tbrSep01;
        private ToolStripSeparator tbrSep02;
        private ToolStripSeparator tbrSep03;
        private ToolStrip Toolbars;

        public FormHistoryLister(string ps_InvoiceCode)
        {
            this.is_HistoryType = "";
            this.is_InvoiceOrder = "";
            this.id_Ngay_Ct1 = AppInstance.StartWorkingDate;
            this.id_Ngay_Ct2 = AppInstance.EndWorkingDate;
            this.InitializeComponent();
            this.grdMaster.AutoGenerateColumns = false;
            this.grdDetail.AutoGenerateColumns = false;
            this.InvoiceCode = ps_InvoiceCode;
            this.OnResetControls();
        }

        public FormHistoryLister(AppInvoiceLib po_AppInvoiceLib, object ps_InvoiceOrder)
        {
            this.is_HistoryType = "";
            this.is_InvoiceOrder = "";
            this.id_Ngay_Ct1 = AppInstance.StartWorkingDate;
            this.id_Ngay_Ct2 = AppInstance.EndWorkingDate;
            this.InitializeComponent();
            this.grdMaster.AutoGenerateColumns = false;
            this.grdDetail.AutoGenerateColumns = false;
            this.AppInvoiceParameters = po_AppInvoiceLib;
            this.is_InvoiceOrder = ps_InvoiceOrder.ToString();
            this.OnResetControls();
            this.OnFillDataOneRow();
            this.OnFillInvoice(this.HistoryType);
            this.btnRestore.Enabled = false;
            this.btnFilter.Enabled = false;
            this.grdMaster.DataSource = new BindingSource(this.oMasterTable, this.oMasterTable.TableName);
            this.grdDetail.DataSource = new BindingSource(this.oDetailTable, this.oDetailTable.TableName);
        }

        public FormHistoryLister(AppInvoiceLib po_AppInvoiceLib, string ps_HistoryType, object ps_InvoiceOrder)
        {
            this.is_HistoryType = "";
            this.is_InvoiceOrder = "";
            this.id_Ngay_Ct1 = AppInstance.StartWorkingDate;
            this.id_Ngay_Ct2 = AppInstance.EndWorkingDate;
            this.InitializeComponent();
            this.grdMaster.AutoGenerateColumns = false;
            this.grdDetail.AutoGenerateColumns = false;
            this.AppInvoiceParameters = po_AppInvoiceLib;
            this.is_InvoiceOrder = ps_InvoiceOrder.ToString();
            this.HistoryType = ps_HistoryType;
            this.OnResetControls();
            this.OnFillDataOneRow();
            this.OnFillInvoice(ps_HistoryType);
            this.btnRestore.Enabled = false;
            this.btnFilter.Enabled = false;
            this.grdMaster.DataSource = new BindingSource(this.oMasterTable, this.oMasterTable.TableName);
            this.grdDetail.DataSource = new BindingSource(this.oDetailTable, this.oDetailTable.TableName);
        }

        public FormHistoryLister(string ps_InvoiceCode, object pd_Ngay_Ct1, object pd_Ngay_Ct2)
        {
            this.is_HistoryType = "";
            this.is_InvoiceOrder = "";
            this.id_Ngay_Ct1 = AppInstance.StartWorkingDate;
            this.id_Ngay_Ct2 = AppInstance.EndWorkingDate;
            this.InitializeComponent();
            this.grdMaster.AutoGenerateColumns = false;
            this.grdDetail.AutoGenerateColumns = false;
            this.InvoiceCode = ps_InvoiceCode;
            this.id_Ngay_Ct1 = pd_Ngay_Ct1;
            this.id_Ngay_Ct2 = pd_Ngay_Ct2;
            this.OnFillDataAll();
            this.grdMaster.DataSource = new BindingSource(this.oMasterTable, this.oMasterTable.TableName);
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnFilter_Click(object sender, EventArgs e)
        {
            if (this.btnFilter.Enabled)
            {
                this.OnFilter();
            }
        }

        private void btnRestore_Click(object sender, EventArgs e)
        {
            if (this.AppInvoiceParameters.AllowAddInvoice && this.btnRestore.Enabled)
            {
                this.OnRestore();
            }
        }

        private void btnView_Click(object sender, EventArgs e)
        {
            if (this.btnView.Enabled)
            {
                this.OnView();
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void grdDetail_DoubleClick(object sender, EventArgs e)
        {
            this.OnView();
        }

        private void grdMaster_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            if ((this.grdMaster.CurrentRow != null) && (this.grdMaster.CurrentRow.DataBoundItem != null))
            {
                DataRow row = ((DataRowView) this.grdMaster.CurrentRow.DataBoundItem).Row;
                this.InvoiceOrder = row["Stt"].ToString();
            }
        }

        private void InitializeComponent()
        {
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormHistoryLister));
            this.Toolbars = new System.Windows.Forms.ToolStrip();
            this.btnView = new System.Windows.Forms.ToolStripButton();
            this.tbrSep01 = new System.Windows.Forms.ToolStripSeparator();
            this.btnRestore = new System.Windows.Forms.ToolStripButton();
            this.tbrSep02 = new System.Windows.Forms.ToolStripSeparator();
            this.btnFilter = new System.Windows.Forms.ToolStripButton();
            this.tbrSep03 = new System.Windows.Forms.ToolStripSeparator();
            this.btnClose = new System.Windows.Forms.ToolStripButton();
            this.GridContainer = new System.Windows.Forms.SplitContainer();
            this.grdMaster = new QMVnSoft.Controls.GridControl();
            this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column6 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column7 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column8 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.grdDetail = new QMVnSoft.Controls.GridControl();
            this.Column9 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column10 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column11 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column12 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column13 = new QMVnSoft.Controls.ChildGridControls.NumericColumn();
            this.Column14 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column15 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Toolbars.SuspendLayout();
            this.GridContainer.Panel1.SuspendLayout();
            this.GridContainer.Panel2.SuspendLayout();
            this.GridContainer.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.grdMaster)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.grdDetail)).BeginInit();
            this.SuspendLayout();
            // 
            // Toolbars
            // 
            this.Toolbars.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.btnView,
            this.tbrSep01,
            this.btnRestore,
            this.tbrSep02,
            this.btnFilter,
            this.tbrSep03,
            this.btnClose});
            this.Toolbars.Location = new System.Drawing.Point(0, 0);
            this.Toolbars.Name = "Toolbars";
            this.Toolbars.Size = new System.Drawing.Size(794, 25);
            this.Toolbars.TabIndex = 0;
            this.Toolbars.Text = "Toolbars";
            // 
            // btnView
            // 
            this.btnView.Image = global::QMVnSoft.Properties.Resources.PREVIEW1;
            this.btnView.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnView.Name = "btnView";
            this.btnView.Size = new System.Drawing.Size(51, 22);
            this.btnView.Text = "Xem";
            this.btnView.ToolTipText = "Xem (F3)";
            this.btnView.Click += new System.EventHandler(this.btnView_Click);
            // 
            // tbrSep01
            // 
            this.tbrSep01.Name = "tbrSep01";
            this.tbrSep01.Size = new System.Drawing.Size(6, 25);
            // 
            // btnRestore
            // 
            this.btnRestore.Enabled = false;
            this.btnRestore.Image = global::QMVnSoft.Properties.Resources.RESTORE;
            this.btnRestore.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnRestore.Name = "btnRestore";
            this.btnRestore.Size = new System.Drawing.Size(81, 22);
            this.btnRestore.Text = "Khôi phục";
            this.btnRestore.ToolTipText = "Khôi phục (Ctrl+F2)";
            this.btnRestore.Click += new System.EventHandler(this.btnRestore_Click);
            // 
            // tbrSep02
            // 
            this.tbrSep02.Name = "tbrSep02";
            this.tbrSep02.Size = new System.Drawing.Size(6, 25);
            // 
            // btnFilter
            // 
            this.btnFilter.Image = global::QMVnSoft.Properties.Resources.FILTER1;
            this.btnFilter.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnFilter.Name = "btnFilter";
            this.btnFilter.Size = new System.Drawing.Size(46, 22);
            this.btnFilter.Text = "Lọc";
            this.btnFilter.ToolTipText = "Lọc (F9)";
            this.btnFilter.Click += new System.EventHandler(this.btnFilter_Click);
            // 
            // tbrSep03
            // 
            this.tbrSep03.Name = "tbrSep03";
            this.tbrSep03.Size = new System.Drawing.Size(6, 25);
            this.tbrSep03.Visible = false;
            // 
            // btnClose
            // 
            this.btnClose.Image = global::QMVnSoft.Properties.Resources.CLOSE;
            this.btnClose.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnClose.Name = "btnClose";
            this.btnClose.Size = new System.Drawing.Size(58, 22);
            this.btnClose.Text = "Thoát";
            this.btnClose.ToolTipText = "Thoát (Esc)";
            this.btnClose.Visible = false;
            this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
            // 
            // GridContainer
            // 
            this.GridContainer.Dock = System.Windows.Forms.DockStyle.Fill;
            this.GridContainer.IsSplitterFixed = true;
            this.GridContainer.Location = new System.Drawing.Point(0, 25);
            this.GridContainer.Name = "GridContainer";
            this.GridContainer.Orientation = System.Windows.Forms.Orientation.Horizontal;
            // 
            // GridContainer.Panel1
            // 
            this.GridContainer.Panel1.Controls.Add(this.grdMaster);
            // 
            // GridContainer.Panel2
            // 
            this.GridContainer.Panel2.Controls.Add(this.grdDetail);
            this.GridContainer.Size = new System.Drawing.Size(794, 507);
            this.GridContainer.SplitterDistance = 237;
            this.GridContainer.SplitterWidth = 1;
            this.GridContainer.TabIndex = 3;
            // 
            // grdMaster
            // 
            this.grdMaster.AllowUserToAddRows = false;
            this.grdMaster.AllowUserToDeleteRows = false;
            this.grdMaster.CheckAutoSize = true;
            this.grdMaster.CheckColor = false;
            this.grdMaster.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.grdMaster.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.Column1,
            this.Column2,
            this.Column3,
            this.Column4,
            this.Column5,
            this.Column6,
            this.Column7,
            this.Column8});
            this.grdMaster.Dock = System.Windows.Forms.DockStyle.Fill;
            this.grdMaster.Font = new System.Drawing.Font("Arial", 8.25F);
            this.grdMaster.Location = new System.Drawing.Point(0, 0);
            this.grdMaster.Name = "grdMaster";
            this.grdMaster.ReadOnly = true;
            this.grdMaster.Size = new System.Drawing.Size(794, 237);
            this.grdMaster.TabIndex = 0;
            this.grdMaster.CellEnter += new System.Windows.Forms.DataGridViewCellEventHandler(this.grdMaster_CellEnter);
            // 
            // Column1
            // 
            this.Column1.DataPropertyName = "Ngay_Ct";
            this.Column1.HeaderText = "Ngày";
            this.Column1.Name = "Column1";
            this.Column1.ReadOnly = true;
            this.Column1.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column1.Width = 62;
            // 
            // Column2
            // 
            this.Column2.DataPropertyName = "So_Ct";
            this.Column2.HeaderText = "Số";
            this.Column2.Name = "Column2";
            this.Column2.ReadOnly = true;
            this.Column2.Width = 70;
            // 
            // Column3
            // 
            this.Column3.DataPropertyName = "Dien_Giai";
            this.Column3.HeaderText = "Diễn giải (VN)";
            this.Column3.Name = "Column3";
            this.Column3.ReadOnly = true;
            this.Column3.Width = 139;
            // 
            // Column4
            // 
            this.Column4.DataPropertyName = "Desc_EN";
            this.Column4.HeaderText = "Diễn giải (EN)";
            this.Column4.Name = "Column4";
            this.Column4.ReadOnly = true;
            this.Column4.Width = 138;
            // 
            // Column5
            // 
            this.Column5.DataPropertyName = "Creator";
            this.Column5.HeaderText = "Người lập";
            this.Column5.Name = "Column5";
            this.Column5.ReadOnly = true;
            this.Column5.Width = 60;
            // 
            // Column6
            // 
            this.Column6.DataPropertyName = "CrtTime";
            this.Column6.HeaderText = "Thời điểm lập";
            this.Column6.Name = "Column6";
            this.Column6.ReadOnly = true;
            this.Column6.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column6.Width = 111;
            // 
            // Column7
            // 
            this.Column7.DataPropertyName = "Deletor";
            this.Column7.HeaderText = "Người xóa";
            this.Column7.Name = "Column7";
            this.Column7.ReadOnly = true;
            this.Column7.Width = 60;
            // 
            // Column8
            // 
            this.Column8.DataPropertyName = "DelTime";
            this.Column8.HeaderText = "Thời điểm xóa";
            this.Column8.Name = "Column8";
            this.Column8.ReadOnly = true;
            this.Column8.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column8.Width = 111;
            // 
            // grdDetail
            // 
            this.grdDetail.AllowUserToAddRows = false;
            this.grdDetail.AllowUserToDeleteRows = false;
            this.grdDetail.CheckAutoSize = true;
            this.grdDetail.CheckColor = false;
            this.grdDetail.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.grdDetail.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.Column9,
            this.Column10,
            this.Column11,
            this.Column12,
            this.Column13,
            this.Column14,
            this.Column15});
            this.grdDetail.Dock = System.Windows.Forms.DockStyle.Fill;
            this.grdDetail.Font = new System.Drawing.Font("Arial", 8.25F);
            this.grdDetail.Location = new System.Drawing.Point(0, 0);
            this.grdDetail.Name = "grdDetail";
            this.grdDetail.ReadOnly = true;
            this.grdDetail.Size = new System.Drawing.Size(794, 269);
            this.grdDetail.TabIndex = 0;
            this.grdDetail.DoubleClick += new System.EventHandler(this.grdDetail_DoubleClick);
            // 
            // Column9
            // 
            this.Column9.DataPropertyName = "Ngay_Ct";
            this.Column9.HeaderText = "Ngày";
            this.Column9.Name = "Column9";
            this.Column9.ReadOnly = true;
            this.Column9.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column9.Width = 62;
            // 
            // Column10
            // 
            this.Column10.DataPropertyName = "So_Ct";
            this.Column10.HeaderText = "Số";
            this.Column10.Name = "Column10";
            this.Column10.ReadOnly = true;
            this.Column10.Width = 70;
            // 
            // Column11
            // 
            this.Column11.DataPropertyName = "Dien_Giai";
            this.Column11.HeaderText = "Diễn giải (VN)";
            this.Column11.Name = "Column11";
            this.Column11.ReadOnly = true;
            this.Column11.Width = 172;
            // 
            // Column12
            // 
            this.Column12.DataPropertyName = "Desc_EN";
            this.Column12.HeaderText = "Diễn giải (EN)";
            this.Column12.Name = "Column12";
            this.Column12.ReadOnly = true;
            this.Column12.Width = 171;
            // 
            // Column13
            // 
            this.Column13.DataPropertyName = "TTien_Nt";
            dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            this.Column13.DefaultCellStyle = dataGridViewCellStyle1;
            this.Column13.HeaderText = "Tổng tiền";
            this.Column13.Name = "Column13";
            this.Column13.ReadOnly = true;
            this.Column13.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column13.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column13.UserTextNumericFormat  = QMVnSoft.AppInstance.TextNumericFormat.ForeignAmount;
            this.Column13.Width = 105;
            // 
            // Column14
            // 
            this.Column14.DataPropertyName = "Updator";
            this.Column14.HeaderText = "Người sửa";
            this.Column14.Name = "Column14";
            this.Column14.ReadOnly = true;
            this.Column14.Width = 60;
            // 
            // Column15
            // 
            this.Column15.DataPropertyName = "UdtTime";
            this.Column15.HeaderText = "Thời điểm sửa";
            this.Column15.Name = "Column15";
            this.Column15.ReadOnly = true;
            this.Column15.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column15.Width = 111;
            // 
            // FormHistoryLister
            // 
            this.ClientSize = new System.Drawing.Size(794, 532);
            this.Controls.Add(this.GridContainer);
            this.Controls.Add(this.Toolbars);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MinimumSize = new System.Drawing.Size(802, 566);
            this.Name = "FormHistoryLister";
            this.Text = "Lịch sử chứng từ";
            this.Toolbars.ResumeLayout(false);
            this.Toolbars.PerformLayout();
            this.GridContainer.Panel1.ResumeLayout(false);
            this.GridContainer.Panel2.ResumeLayout(false);
            this.GridContainer.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.grdMaster)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.grdDetail)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        private void OnFillDataAll()
        {
            this.oMasterTable = this.AppInvoiceParameters.AppInvoiceMethod.GetHistoryTable(AppInstance.Subsidiary, this.InvoiceCode, this.id_Ngay_Ct1, this.id_Ngay_Ct2);
        }

        private void OnFillDataOneRow()
        {
            this.oMasterTable = this.AppInvoiceParameters.AppInvoiceMethod.GetHistoryTable(this.InvoiceOrder);
        }

        private void OnFillInvoice()
        {
            string str = "";
            str = ((DataRowView) this.grdMaster.CurrentRow.DataBoundItem).Row["Ma_Nvu"].ToString();
            this.oDetailTable = this.AppInvoiceParameters.AppInvoiceMethod.GetMasterHistoryTable(str, this.InvoiceOrder);
            if (this.oDetailTable != null)
            {
                this.grdDetail.DataSource = new BindingSource(this.oDetailTable, this.oDetailTable.TableName);
            }
            else
            {
                this.grdDetail.DataSource = null;
            }
        }

        private void OnFillInvoice(string ps_Ma_Nvu)
        {
            this.oDetailTable = this.AppInvoiceParameters.AppInvoiceMethod.GetMasterHistoryTable(ps_Ma_Nvu, this.InvoiceOrder);
        }

        public bool OnFilter()
        {
            FormHistoryFilter filter = new FormHistoryFilter();
            filter.InvoiceCode = this.InvoiceCode;
            filter.Ngay_Ct1 = this.id_Ngay_Ct1;
            filter.Ngay_Ct2 = this.id_Ngay_Ct2;
            filter.ShowDialog();
            if (filter.CheckAccepted)
            {
                this.id_Ngay_Ct1 = filter.Ngay_Ct1;
                this.id_Ngay_Ct2 = filter.Ngay_Ct2;
                this.OnFillDataAll();
                this.grdMaster.DataSource = new BindingSource(this.oMasterTable, this.oMasterTable.TableName);
                return true;
            }
            return false;
        }

        private void OnResetControls()
        {
            if (!this.AppInvoiceParameters.BilingualUsed)
            {
                this.grdMaster.Columns[3].Visible = false;
                this.grdMaster.Columns[2].Width += this.grdMaster.Columns[3].Width;
                this.grdDetail.Columns[3].Visible = false;
                this.grdDetail.Columns[2].Width += this.grdDetail.Columns[3].Width;
            }
        }

        internal void OnRestore()
        {
            if (((this.grdDetail.CurrentRow != null) && (this.grdDetail.CurrentRow.DataBoundItem != null)) && (MessageBox.Show("Bạn có thực sư muốn phục hồi không?", AppInstance.SoftwareName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.No))
            {
                DataRow row = ((DataRowView) this.grdDetail.CurrentRow.DataBoundItem).Row;
                this.AppInvoiceParameters.AppInvoiceMethod.Restore(this.HistoryType, AppInstance.UserName, this.InvoiceOrder, row["Stt_Log"]);
            }
        }

        internal void OnView()
        {
            if ((this.grdDetail.CurrentRow != null) && (this.grdDetail.CurrentRow.DataBoundItem != null))
            {
                DataRow row = ((DataRowView) this.grdDetail.CurrentRow.DataBoundItem).Row;
                if (this.HistoryType == "T")
                {
                    FormVATViewer viewer = new FormVATViewer();
                    viewer.AppInvoiceParameters.HistoryType = this.HistoryType;
                    viewer.InvoiceLogOrder = row["Stt_Log"];
                    viewer.OnShow();
                    viewer.Show();
                }
                else
                {
                    FormHistoryViewer viewer2 = null;
                    if (this.HistoryType == "K")
                    {
                        viewer2 = new FormCTKTViewer();
                    }
                    else if (this.HistoryType == "M")
                    {
                        viewer2 = new FormCTMHViewer();
                    }
                    else if (this.HistoryType == "B")
                    {
                        viewer2 = new FormCTBHViewer();
                    }
                    else if (this.HistoryType == "Q")
                    {
                        viewer2 = new FormCTBGViewer();
                    }
                    else if (this.HistoryType == "D")
                    {
                        viewer2 = new FormCTDHViewer();
                    }
                    else if (this.HistoryType == "N")
                    {
                        viewer2 = new FormCTNXViewer();
                    }
                    else if (this.HistoryType == "Y")
                    {
                        viewer2 = new FormCTYCMViewer();
                    }
                    else if (this.HistoryType == "W")
                    {
                        viewer2 = new FormCTKHOViewer();
                    }
                    else if (this.HistoryType == "P")
                    {
                        viewer2 = new FormCTTPViewer();
                    }
                    else if (this.HistoryType == "S")
                    {
                        viewer2 = new FormCTSXViewer();
                    }
                    else if (this.HistoryType == "O")
                    {
                        viewer2 = new FormCTNBViewer();
                    }
                    if (viewer2 != null)
                    {
                        viewer2.AppInvoiceParameters = this.AppInvoiceParameters;
                        viewer2.AppInvoiceParameters.HistoryType = this.HistoryType;
                        viewer2.InvoiceLogOrder = row["Stt_Log"];
                        viewer2.OnShow();
                        viewer2.Show();
                    }
                }
            }
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            switch (keyData)
            {
                case Keys.Escape:
                    base.Close();
                    return true;

                case Keys.F3:
                    if (this.btnView.Enabled)
                    {
                        this.OnView();
                    }
                    return true;

                case Keys.F9:
                    if (this.btnFilter.Enabled)
                    {
                        this.OnFilter();
                    }
                    return true;

                case (Keys.Control | Keys.F2):
                    if (this.AppInvoiceParameters.AllowAddInvoice && this.btnRestore.Enabled)
                    {
                        this.OnRestore();
                    }
                    return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        [Category("History properties"), Browsable(false), Description("The parameters that declare by system, user, invoice code."), DefaultValue((string) null)]
        public AppInvoiceLib AppInvoiceParameters
        {
            get
            {
                if (this.oAppInvoiceLib == null)
                {
                    this.AppInvoiceParameters = new AppInvoiceLib();
                }
                return this.oAppInvoiceLib;
            }
            set
            {
                this.oAppInvoiceLib = value;
            }
        }

        [Description("The transaction type."), Browsable(false), Category("History viewer properties"), DefaultValue((string) null)]
        public string HistoryType
        {
            get
            {
                if (string.IsNullOrEmpty(this.is_HistoryType))
                {
                    return this.AppInvoiceParameters.HistoryType;
                }
                return this.is_HistoryType;
            }
            set
            {
                if (this.is_HistoryType != value)
                {
                    this.is_HistoryType = value;
                }
            }
        }

        [Category("History properties"), DefaultValue(""), Browsable(false), Description("The current invoice code to edit or add.")]
        public string InvoiceCode
        {
            get
            {
                if (this.AppInvoiceParameters == null)
                {
                    return "";
                }
                return this.AppInvoiceParameters.InvoiceCode;
            }
            set
            {
                if (this.AppInvoiceParameters != null)
                {
                    this.AppInvoiceParameters.InvoiceCode = value;
                }
            }
        }

        public string InvoiceOrder
        {
            get
            {
                return this.is_InvoiceOrder;
            }
            set
            {
                if (this.is_InvoiceOrder != value)
                {
                    this.is_InvoiceOrder = value;
                    this.OnFillInvoice();
                }
            }
        }
    }
}

